<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>客户报备</title>
<meta name="viewport" content="width=100%, initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="/lib/weix/style/weui.min.css">
<link rel="stylesheet" href="/css/fonts.css">
<link rel="stylesheet" href="/css/comm.css">
<link rel="stylesheet" href="/css/form_hej.css">
</head>

<body>
<div class="weui-cells weui-cells_form tbd">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label"><i class="icon-user "></i></label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" placeholder="客户姓名" id="J_name">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label"><i class="icon-phone"></i></label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="tel" placeholder="客户手机" id="J_phone" maxlength="11">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="" class="weui-label"><i class="icon-position"></i></label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" placeholder="楼盘地址，例如：万科城3栋201" id="J_address">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="" class="weui-label"><i class="icon-date"></i></label></div>
        <div class="weui-cell__bd" style="margin-top:-5px; padding-bottom:3px;">
            <input class="weui-input" type="date" value="" placeholder="预计客户到店时间" id="J_arrive">
        </div>
    </div>
</div>
<input type="hidden" id = "J_uid" value ="${uid}" />

<div class="weui-cells__tips" style="padding-left:60px;">
· 预计客户到店时间<br />
· 报备<span id="J_riq">-</span>天(含)内有效，超过期限成交将无法获得奖励
</div>

<div class="weui-btn-area">
    <a class="weui-btn weui-btn_primary" href="javascript:" id="J_submit">确定</a>
</div>

<script src="/js/zepto.min.js"></script>
<script src="https://res.wx.qq.com/open/libs/weuijs/1.0.0/weui.min.js"></script>
<script src="/js/comm.js"></script>
<script type="text/javascript">
//查看设置
function config_look(){
	var data = {};
	var url = "/config/indate";
	$.ajax({
		type: "POST",
		async: false,
		dataType: 'json',
		contentType: "application/json; charset=utf-8",
		data: JSON.stringify(data),
		url: url,
		success: function(res){
			if(res.code == 200){
				var datas = res.data
				$('#J_riq').html(datas)	//报备有效期
			}else{
				weui.topTips('报备有效期获取失败，请联系管理员');
			}
		},
		error: function(){

		},
		complete: function(){
		}
	});
}


$(function(){		
	sessionStorage.setItem("need-refresh", true);  //返回上一页刷新
	config_look() //报备日期
	
	//提交操作
	$(document).on('click','#J_submit',function(){
		var name_data = $('#J_name').val().trim();
		var tel_data = $('#J_phone').val().trim();
		var diz_data = $('#J_address').val().trim();
		var date_data = $('#J_arrive').val().trim();
		
		if(!name(name_data)){
			return false
		}

		if(!tel(tel_data)){
			return false
		}

		if(diz_data.trim() == ''){
			weui.topTips('请填写正确的楼盘信息');
			return false		
		}
		
		if(date_data.trim() == ''){
			weui.topTips('请填写预计到店时间');
			return false		
		}
		
		
		
		weui.dialog({
			title: '提交报备',
			content: '是否确认提交报备？',
			className: 'custom-classname',
			buttons: [{
				label: '取消',
				type: 'default',
				onClick: function () {}
			}, {
				label: '确定',
				type: 'primary',
				onClick: function () {
					
					var loading = weui.loading('数据提交中', {
						className: ''
					});
					
					var data = {name:$("#J_name").val(),phone:$("#J_phone").val(),address:$("#J_address").val(),arrive:$("#J_arrive").val(),uid:$("#J_uid").val()};
					var url = "/customer/customer_edit";
					$.ajax({
						type: "POST",
						async: false,
						dataType: 'json',
						contentType: "application/json; charset=utf-8",
						data: JSON.stringify(data),
						url: url,
						success: function(res){
							if(res.code == 200){
								weui.toast('提交成功', {
									duration: 1500,
									className: 'custom-classname',
									callback: function(){ 
										location.replace('/customerPage/customerList')
									}
								});
							}else{
								weui.topTips(res.msg);
							}
						},
						error: function(){
						
						},
						complete: function(){
							loading.hide();	
						}
					});	
					
				}
			}]
		});
	
	}) 
	
});
</script>
</body>
</html>